<?php

	include_once("./db.php"); 
	
	$userId = $_SESSION["user"]["Id"];

	$res = db_select("SELECT 
		m.Id,
		m.Name,
		(SELECT 1 FROM UserMode um WHERE um.UserId = $userId) as Selected
		FROM Mode m, UserElement aa 
		ORDER BY Selected, m.Name");

	while($item = mysql_fetch_array($res, MYSQL_ASSOC))
		$ret["Modes"][] = $item;
	
	echo json_result_encode($ret);

?>